//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "InverseCumulativePoisson.h"
using namespace Cephei::QL::Math::Distributions;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (Microsoft::FSharp::Core::FSharpOption<Double>^ lambda) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phInverseCumulativePoisson = NULL;
#endif
        QuantLib::Real _lambda = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (lambda) ? (QuantLib::Real)ValueHelper::Convert (lambda->Value) : 1.0); //4
        _ppInverseCumulativePoisson = new boost::shared_ptr<QuantLib::InverseCumulativePoisson> (new QuantLib::InverseCumulativePoisson ( _lambda ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (boost::shared_ptr<QuantLib::InverseCumulativePoisson>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativePoisson = NULL;
#endif
	_ppInverseCumulativePoisson = &childNative;
    
}
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (QuantLib::InverseCumulativePoisson& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phInverseCumulativePoisson = NULL;
#endif
	_ppInverseCumulativePoisson = new boost::shared_ptr<QuantLib::InverseCumulativePoisson> (&childNative);
    
    _InverseCumulativePoissonOwner = owner;
    
}

Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (CInverseCumulativePoisson^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativePoisson = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppInverseCumulativePoisson = new boost::shared_ptr<QuantLib::InverseCumulativePoisson> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativePoisson = NULL;
#endif
	if (!t->IsSubclassOf(CInverseCumulativePoisson::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (QuantLib::Handle<QuantLib::InverseCumulativePoisson>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phInverseCumulativePoisson = &childNative;
	_ppInverseCumulativePoisson = &static_cast<boost::shared_ptr<QuantLib::InverseCumulativePoisson>>(childNative.currentLink());
    
    _InverseCumulativePoissonOwner = owner;
}
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (QuantLib::Handle<QuantLib::InverseCumulativePoisson> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phInverseCumulativePoisson = &childNative;
	_ppInverseCumulativePoisson = &static_cast<boost::shared_ptr<QuantLib::InverseCumulativePoisson>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::CInverseCumulativePoisson (QuantLib::InverseCumulativePoisson childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phInverseCumulativePoisson = NULL;
#endif
	_ppInverseCumulativePoisson = new boost::shared_ptr<QuantLib::InverseCumulativePoisson> (new QuantLib::InverseCumulativePoisson (childNative));
    
}
#endif

Cephei::QL::Math::Distributions::CInverseCumulativePoisson::~CInverseCumulativePoisson ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppInverseCumulativePoisson != NULL)
    {
	    delete _ppInverseCumulativePoisson;
        _ppInverseCumulativePoisson = NULL;
    }
}
Cephei::QL::Math::Distributions::CInverseCumulativePoisson::!CInverseCumulativePoisson ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppInverseCumulativePoisson != NULL)
    {
	    delete _ppInverseCumulativePoisson;
    }
}
QuantLib::InverseCumulativePoisson& Cephei::QL::Math::Distributions::CInverseCumulativePoisson::GetReference ()
{
    if (_ppInverseCumulativePoisson == NULL) throw gcnew NativeNullException ();
	return **_ppInverseCumulativePoisson;
}
boost::shared_ptr<QuantLib::InverseCumulativePoisson>& Cephei::QL::Math::Distributions::CInverseCumulativePoisson::GetShared ()
{
    if (_ppInverseCumulativePoisson == NULL) throw gcnew NativeNullException ();
	return *_ppInverseCumulativePoisson;
}
QuantLib::InverseCumulativePoisson* Cephei::QL::Math::Distributions::CInverseCumulativePoisson::GetPointer ()
{
    if (_ppInverseCumulativePoisson == NULL) throw gcnew NativeNullException ();
	return &**_ppInverseCumulativePoisson;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::InverseCumulativePoisson>& Cephei::QL::Math::Distributions::CInverseCumulativePoisson::GetHandle ()
{
	if (_phInverseCumulativePoisson == NULL)
	{
		_phInverseCumulativePoisson = new Handle<QuantLib::InverseCumulativePoisson> (*_ppInverseCumulativePoisson);
	}
	return *_phInverseCumulativePoisson;
}
#endif
bool Cephei::QL::Math::Distributions::CInverseCumulativePoisson::HasNative () 
{
	return (_ppInverseCumulativePoisson != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Distributions::IInverseCumulativePoisson^ Cephei::QL::Math::Distributions::CInverseCumulativePoisson_Factory::Create (Microsoft::FSharp::Core::FSharpOption<Double>^ lambda)
{
    return gcnew CInverseCumulativePoisson ( lambda);
}
